/**
 * @param {number[]} stones
 * @return {number}
 */
var lastStoneWeight = function(stones) {
  if (stones.length <= 1) return stones[0] || 0
  stones.sort((a, b) => a - b)
  let tmp = stones[stones.length - 1] - stones[stones.length - 2]
  stones.length -= 2
  if (tmp > 0) {
    stones.push(tmp)
  }
  return lastStoneWeight(stones)
}

console.log(lastStoneWeight([1, 1, 3, 3, 4, 4]))
